<?php

namespace apiend\modules\setting\models;

use Yii;
use common\helpers\Url;
use common\models\book\Stage;

/**
 * 品牌设置模型
 * 
 * @author emhome <emhome@163.com>
 * @since 1.0
 */
class StageForm extends Stage {

    /**
     * @inheritdoc
     */
    public function typecastAttributes() {
        return [
            parent::EVENT_BEFORE_VALIDATE => [
                [
                    'attributes' => ['start_hour', 'end_hour'],
                    'type' => function ($event, $attribute) {
                        $datetime = date('Y-m-d ') . $this->$attribute . ':00';
                        return strtotime($datetime) - strtotime('today');
                    },
                ],
                [
                    'attributes' => ['name'],
                    'type' => function ($event, $attribute) {
                        return date('H:i', $this->start_hour + strtotime('today')) . '-' . date('H:i', $this->end_hour + strtotime('today'));
                    },
                ],
            ],
            parent::EVENT_AFTER_FIND => [
                [
                    'attributes' => ['start_hour', 'end_hour'],
                    'type' => function ($event, $attribute) {
                        return gmdate('H:i', $this->$attribute);
                    },
                ],
            ]
        ];
    }

}
